<#assign module="driver"/>

<@override name="header">
    <link rel="stylesheet" href="${ctx}/assets/css/datetimepicker.css">
    <link rel="stylesheet" href="${ctx}/assets/css/bootstrap-multiselect.css">
    <style>
        .input-query-multiple {
            min-width: 300px;
            padding: 0px 0px;
            height: auto;
            margin-top: 20px;
        }
    </style>
</@override>
<@override name="body">
    <div class="tabbable tabs-left">
        <div class="row">
            <div class="col-xs-12 col-md-10">
                <div class="orders-navt">
                    <ul class="orders-nav">
<#--                        <@shiro.hasPermission name='servicePersonal'>-->
<#--                            <li style="width:90px;"><a href="${ctx}/driver/list">服务人员</a></li>-->
<#--                        </@shiro.hasPermission>-->
<#--                        <@shiro.hasPermission name='driverapply'>-->
<#--                            <li><a href="${ctx}/driverapply/list">申请</a></li>-->
<#--                        </@shiro.hasPermission>-->
<#--                        <@shiro.hasPermission name='callLog'>-->
<#--                            <li style="width:90px;"><a href="${ctx}/driver/recordlist">通话记录</a></li>-->
<#--                        </@shiro.hasPermission>-->
<#--                        <@shiro.hasPermission name='notice'>-->
<#--                            <li><a href="${ctx}/notice/list">通知</a></li>-->
<#--                        </@shiro.hasPermission>-->
<#--                        <@shiro.hasPermission name='announcement'>-->
<#--                            <li style="width:90px;" class="orders-click"><a href="${ctx}/driver/announcementList">公告</a>-->
<#--                            </li>-->
<#--                        </@shiro.hasPermission>-->
<#--                        <@shiro.hasPermission name='drivermoney'>-->
<#--                            <li style="width:90px;"><a href="${ctx}/driver/drivermoney">批量操作</a></li>-->
<#--                        </@shiro.hasPermission>-->
<#--                        <@shiro.hasPermission name='drivermoney' >-->
<#--                            <li style="width:110px;"><a href="${ctx}/driver/driverReward">服务人员奖励</a></li>-->
<#--                        </@shiro.hasPermission>-->

                        <@shiro.hasPermission name='servicePersonal'>
                            <li style="width:90px;"><a href="${ctx}/driver/list" class="orders-click-a">服务人员</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='drivergrade'>
                            <li style="width:110px;"><a href="${ctx}/drivergrade/list">服务人员等级</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='driverapply'>
                            <li><a href="${ctx}/driverapply/list">申请</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='callLog'>
                            <li style="width:90px;"><a href="${ctx}/driver/recordlist">通话记录</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='notice'>
                            <li><a href="${ctx}/notice/list">通知</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='announcement'>
                            <li style="width:90px;" class="orders-click"><a href="${ctx}/driver/announcementList">公告</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='drivermoney'>
                            <li style="width:90px;"><a href="${ctx}/driver/drivermoney">批量操作</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='drivermoney'>
                            <li style="width:110px;"><a href="${ctx}/driver/driverReward">服务人员奖励</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='driverenchashment'>
                            <li style="width:100px;"><a href="${ctx}/driverenchashment/list">申请提现</a></li>
                            <li style="width:120px;"><a href="${ctx}/driverRebateenchashment/extendList">申请提取推广奖励</a></li>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name='driverloginrecord'>
                            <li style="width:90px;"><a href="${ctx}/driver/loginlist">登录日志</a></li>
                        </@shiro.hasPermission>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="tab-content margin-top">
        <div class="container-fluid" style="border:none;">
            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            服务人员公告
                        </div>
                        <div class="panel-body">
                            <form id="submit_form" class="form-horizontal" method="post">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><em>*</em>公告标题：</label>
                                    <div class="col-sm-6">
                                        <input class="form-control" type="text" id="title" name="title"/>
                                        <span style="color:red">此公告标题用于APP显示</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><em>*</em>公告内容：</label>
                                    <div class="col-sm-6">
                                        <textarea class="form-control" id="content" name="content" rows="8"></textarea>
                                        <span style="color:red">此公告内容用于APP显示</span>
                                        <span class="word_count1"></span>
                                        <span class="word_count2"></span>
                                        <span class="word_surplus"></span>
                                    </div>
                                </div>
                                <@shiro.isMainCompany>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">所属公司：</label>
                                        <div class="col-sm-4">
                                            <select class="form-control" id="companyId" name="companyId">
                                                <option value="">所有公司</option>
                                                <#list companys as company>
                                                    <option value="${company.id}">${company.abbreviation}</option>
                                                </#list>
                                            </select>
                                        </div>
                                    </div>
                                </@shiro.isMainCompany>
                                <div class="form-group" style="margin-left:10px;">
                                    <label class="col-sm-3 control-label"></label>
                                    <input id="submit_button" type="button" class="btn btn-primary" value="发布">
                                    <input type="button" class="btn btn-default"
                                           onclick="window.location.href = '${ctx}/driver/announcementList';"
                                           value="返回">
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</@override>

<@override name="footer">
    <script src="${ctx}/assets/js/bootstrap-multiselect.js"></script>
    <script src="${ctx}/assets/kindeditor/kindeditor-all-min.js"></script>
    <script src="${ctx}/assets/kindeditor/lang/zh_CN.js"></script>
    <script src="${ctx}/assets/js/datepicker.js"></script>
    <script type="text/javascript">
        var save_submit = false;
        KindEditor.ready(function (K) {
            K.create('#content', {
                filterMode: false,
                uploadJson: ctx + '/common/kindeditor/fileupload',
                allowUpload: true,
                fileManagerJson: ctx + '/common/kindeditor/filemanager',
                allowFileManager: true,
                height: 400,
                width: '100%',
                resizeType: 0,
                afterCreate: function () {
                    var self = this;
                    K.ctrl(document, 13, function () {
                        self.sync();
                    });
                    K.ctrl(self.edit.doc, 13, function () {
                        self.sync();
                    });
                },
                afterBlur: function () {
                    this.sync();
                },
                afterChange: function () {
                    var limitNum = 500;
                    if (this.count('text') > limitNum) {
                        $.scojs_message("字数超过限制，请适当删除部分内容", $.scojs_message.TYPE_ERROR);
                    }
                }
            });
        });

        $(document).ready(function () {

            $("#cancel").click(function () {
                $("#dialog_driver").modal("hide");
            });

            function submit() {
                if (save_submit) {
                    var companyId = $("#companyId").val();
                    if (companyId) {
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/driver/announcement",
                            data: {
                                title: $("#title").val(),
                                content: $("#content").val(),
                                companyId: $("#companyId").val()
                            },
                            dataType: "json",
                            success: function (result) {
                                if (result.success) {
                                    $.scojs_message(result.message, $.scojs_message.TYPE_OK);
                                    setTimeout(function () {
                                        window.location.href = '${ctx}/driver/announcementList';
                                    }, 1000);
                                } else {
                                    $.scojs_message(result.message, $.scojs_message.TYPE_ERROR);
                                }
                            }
                        });
                    } else {
                        $.ajax({
                            type: "POST",
                            url: "${ctx}/driver/announcement",
                            data: {title: $("#title").val(), content: $("#content").val()},
                            dataType: "json",
                            success: function (result) {
                                if (result.success) {
                                    $.scojs_message(result.message, $.scojs_message.TYPE_OK);
                                    setTimeout(function () {
                                        window.location.href = '${ctx}/driver/announcementList';
                                    }, 1000);
                                } else {
                                    $.scojs_message(result.message, $.scojs_message.TYPE_ERROR);
                                }
                            }
                        });
                    }

                }
                $("#dialog_driver").modal("hide");
                save_submit = false;
            }

            $("#submit_button").click(function () {
                save_submit = true;
                if ($("#title").val() == null || $("#title").val() == '' || $("#title").val().trim() == '') {
                    $.scojs_message("请输入公告标题", $.scojs_message.TYPE_ERROR);
                    return false;
                }
                if ($("#title").val().length > 20) {
                    $.scojs_message("公告标题不能超过20字符", $.scojs_message.TYPE_ERROR);
                    return false;
                }
                if ($("#content").val() == null || $("#content").val() == '' || $("#content").val().trim() == '') {
                    $.scojs_message("请输入公告内容", $.scojs_message.TYPE_ERROR);
                    return false;
                } else if ($("#content").val() > 500) {
                    $.scojs_message("公告内容过长,请删除部分内容再试", $.scojs_message.TYPE_ERROR);
                    return false;
                }

                submit();
            });
        });
    </script>
</@override>
<@extends name="../layout.ftl"/>